home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_FileRunner.idb / usr / freeware / lib / FileRunner2.5 / chmod.tcl.z / chmod.tcl
Encoding:
Text File  |  1999-01-26  |  9.2 KB  |  262 lines

  1.  
  2. # This dialog got rather large and ugly so it got a file of its own
  3. # I know it can be made shorter with smarter logic, but since it works...
  4.  
  5.  
  6. proc ChmodDialog { filename mode } {
  7.   global glob config chmod_state chmod_orig chmod_action chmod_recurse chmod_cancel
  8.  
  9.   set chmod_cancel 0
  10.  
  11.   set w .chmod_dialog
  12.   toplevel $w -class Dialog
  13.   wm title $w "Change permission flags"
  14.   wm iconname $w "Change permission flags"
  15.   wm resizable $w false false
  16.   wm transient $w [winfo toplevel [winfo parent $w]]
  17.  
  18.   set chmod_orig(user,read) 0
  19.   set chmod_orig(user,write) 0
  20.   set chmod_orig(user,exec) 0
  21.   set chmod_orig(group,read) 0
  22.   set chmod_orig(group,write) 0
  23.   set chmod_orig(group,exec) 0
  24.   set chmod_orig(other,read) 0
  25.   set chmod_orig(other,write) 0
  26.   set chmod_orig(other,exec) 0
  27.   set chmod_orig(special,setuid) 0
  28.   set chmod_orig(special,setgid) 0
  29.   set chmod_orig(special,sticky) 0
  30.  
  31.   if {$mode & 1<<0} { set chmod_orig(other,exec) 1 }
  32.   if {$mode & 1<<1} { set chmod_orig(other,write) 1 }
  33.   if {$mode & 1<<2} { set chmod_orig(other,read) 1 }
  34.   if {$mode & 1<<3} { set chmod_orig(group,exec) 1 }
  35.   if {$mode & 1<<4} { set chmod_orig(group,write) 1 }
  36.   if {$mode & 1<<5} { set chmod_orig(group,read) 1 }
  37.   if {$mode & 1<<6} { set chmod_orig(user,exec) 1 }
  38.   if {$mode & 1<<7} { set chmod_orig(user,write) 1 }
  39.   if {$mode & 1<<8} { set chmod_orig(user,read) 1 }
  40.   if {$mode & 1<<9} { set chmod_orig(special,sticky) 1 }
  41.   if {$mode & 1<<10} { set chmod_orig(special,setgid) 1 }
  42.   if {$mode & 1<<11} { set chmod_orig(special,setuid) 1 }
  43.  
  44.   foreach i [array names chmod_orig] {
  45.     set chmod_state($i) $chmod_orig($i)
  46.   }
  47.  
  48.   frame $w.top
  49.   label $w.top.filename -text $filename -bg white
  50.   pack $w.top.filename -side top -expand 1 -fill x -pady 4
  51.  
  52.   frame $w.mid
  53.   frame $w.mid.user
  54.   label $w.mid.user.title -text User
  55.   pack $w.mid.user.title -side top -anchor w
  56.   checkbutton $w.mid.user.read  -text read -variable  chmod_state(user,read)
  57.   pack $w.mid.user.read -side top -anchor w
  58.   checkbutton $w.mid.user.write -text write -variable chmod_state(user,write)
  59.   pack $w.mid.user.write -side top -anchor w
  60.   checkbutton $w.mid.user.exec  -text exec -variable  chmod_state(user,exec)
  61.   pack $w.mid.user.exec -side top -anchor w
  62.  
  63.   frame $w.mid.group
  64.   label $w.mid.group.title -text Group
  65.   pack $w.mid.group.title -side top -anchor w
  66.   checkbutton $w.mid.group.read  -text read -variable  chmod_state(group,read)
  67.   pack $w.mid.group.read -side top -anchor w
  68.   checkbutton $w.mid.group.write -text write -variable chmod_state(group,write)
  69.   pack $w.mid.group.write -side top -anchor w
  70.   checkbutton $w.mid.group.exec  -text exec -variable  chmod_state(group,exec)
  71.   pack $w.mid.group.exec -side top -anchor w
  72.  
  73.   frame $w.mid.other
  74.   label $w.mid.other.title -text Other
  75.   pack $w.mid.other.title -side top -anchor w
  76.   checkbutton $w.mid.other.read  -text read -variable  chmod_state(other,read)
  77.   pack $w.mid.other.read -side top -anchor w
  78.   checkbutton $w.mid.other.write -text write -variable chmod_state(other,write)
  79.   pack $w.mid.other.write -side top -anchor w
  80.   checkbutton $w.mid.other.exec  -text exec -variable  chmod_state(other,exec)
  81.   pack $w.mid.other.exec -side top -anchor w
  82.  
  83.   frame $w.mid.special
  84.   label $w.mid.special.title -text Special
  85.   pack $w.mid.special.title -side top  -anchor w
  86.   checkbutton $w.mid.special.setuid  -text setuid -variable  chmod_state(special,setuid)
  87.   pack $w.mid.special.setuid -side top -anchor w
  88.   checkbutton $w.mid.special.setgid -text setgid -variable chmod_state(special,setgid)
  89.   pack $w.mid.special.setgid -side top -anchor w
  90.   checkbutton $w.mid.special.sticky  -text sticky -variable  chmod_state(special,sticky)
  91.   pack $w.mid.special.sticky -side top -anchor w
  92.  
  93.   frame $w.bot
  94.   frame $w.bot.action
  95.   label $w.bot.action.title -text Action
  96.   pack $w.bot.action.title -side top -anchor w
  97.   radiobutton $w.bot.action.set -text Set -variable chmod_action -value set -command ChmodSetSet
  98.   pack $w.bot.action.set -side top -anchor w
  99.   radiobutton $w.bot.action.add -text Add -variable chmod_action -value add -command ChmodSetAdd
  100.   pack $w.bot.action.add -side top -anchor w
  101.   radiobutton $w.bot.action.del -text Delete -variable chmod_action -value delete -command ChmodSetDel
  102.   pack $w.bot.action.del -side top -anchor w
  103.   checkbutton $w.bot.action.recurse  -text Recurse -variable chmod_recurse
  104.   pack $w.bot.action.recurse -side top -anchor w
  105.  
  106.   button $w.bot.ok -text Ok -command "set chmod_cancel 0; destroy $w"
  107.   button $w.bot.cancel -text Cancel -command "set chmod_cancel 1; destroy $w"
  108.  
  109.   pack $w.bot.cancel -side right -anchor s 
  110.   pack $w.bot.ok -side right -anchor s 
  111.  
  112.   pack $w.mid.user -side left 
  113.   pack $w.mid.group -side left 
  114.   pack $w.mid.other -side left 
  115.   pack $w.mid.special -side left
  116.   pack $w.bot.action -side left
  117.   pack $w.top -side top -expand 1 -fill x
  118.   pack $w.mid -side top
  119.   pack $w.bot -side top -expand 1 -fill x
  120.  
  121.   $w.bot.action.set select
  122.  
  123.   wm withdraw $w
  124.   update idletasks
  125.   set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
  126.           - [winfo vrootx [winfo parent $w]]]
  127.   set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
  128.           - [winfo vrooty [winfo parent $w]]]
  129.   wm geom $w +$x+$y
  130.   wm deiconify $w
  131.  
  132.   set oldGrab [grab current $w]
  133.   frgrab $w
  134.   set oldena $glob(enableautoupdate)
  135.   set glob(enableautoupdate) 0
  136.   tkwait window $w
  137.   if {$oldGrab != ""} {
  138.     frgrab $oldGrab
  139.   }
  140.  
  141.   # calc chmod arguments
  142.   set chmod_arg ""
  143.   if {$chmod_action == "set" } {
  144.     set user 0
  145.     set group 0
  146.     set other 0
  147.     set special 0
  148.     if {$chmod_state(user,exec)} {set user [expr $user | 1<<0]}
  149.     if {$chmod_state(user,write)} {set user [expr $user | 1<<1]}
  150.     if {$chmod_state(user,read)} {set user [expr $user | 1<<2]}
  151.     if {$chmod_state(group,exec)} {set group [expr $group | 1<<0]}
  152.     if {$chmod_state(group,write)} {set group [expr $group | 1<<1]}
  153.     if {$chmod_state(group,read)} {set group [expr $group | 1<<2]}
  154.     if {$chmod_state(other,exec)} {set other [expr $other | 1<<0]}
  155.     if {$chmod_state(other,write)} {set other [expr $other | 1<<1]}
  156.     if {$chmod_state(other,read)} {set other [expr $other | 1<<2]}
  157.     if {$chmod_state(special,sticky)} {set special [expr $special | 1<<0]}
  158.     if {$chmod_state(special,setgid)} {set special [expr $special | 1<<1]}
  159.     if {$chmod_state(special,setuid)} {set special [expr $special | 1<<2]}
  160.     set chmod_arg "$special$user$group$other"
  161.   } elseif {$chmod_action == "add" } {
  162.     set user ""
  163.     set group ""
  164.     set other ""
  165.     set all ""
  166.     set arg ""
  167.     if {$chmod_state(user,read)} {set user "r$user"}
  168.     if {$chmod_state(user,write)} {set user "w$user"}
  169.     if {$chmod_state(user,exec)} {set user "x$user"}
  170.     if {$chmod_state(group,read)} {set group "r$group"}
  171.     if {$chmod_state(group,write)} {set group "w$group"}
  172.     if {$chmod_state(group,exec)} {set group "x$group"}
  173.     if {$chmod_state(other,read)} {set other "r$other"}
  174.     if {$chmod_state(other,write)} {set other "w$other"}
  175.     if {$chmod_state(other,exec)} {set other "x$other"}
  176.     if {$chmod_state(special,setuid)} {set user "s$user"}
  177.     if {$chmod_state(special,setgid)} {set group "s$group"}
  178.     if {$chmod_state(special,sticky)} {set all "t$all"}
  179.     if {$user != ""} {
  180.       set arg "u+$user"
  181.     }
  182.     if {$group != ""} {
  183.       if {$arg != ""} { set arg ",$arg" }
  184.       set arg "g+$group$arg"
  185.     }
  186.     if {$other != ""} {
  187.       if {$arg != ""} { set arg ",$arg" }
  188.       set arg "o+$other$arg"
  189.     }
  190.     if {$all != ""} {
  191.       if {$arg != ""} { set arg ",$arg" }
  192.       set arg "a+$all$arg"
  193.     }
  194.     set chmod_arg $arg
  195.   } elseif {$chmod_action == "delete" } {
  196.     set user ""
  197.     set group ""
  198.     set other ""
  199.     set all ""
  200.     set arg ""
  201.     if {$chmod_state(user,read)} {set user "r$user"}
  202.     if {$chmod_state(user,write)} {set user "w$user"}
  203.     if {$chmod_state(user,exec)} {set user "x$user"}
  204.     if {$chmod_state(group,read)} {set group "r$group"}
  205.     if {$chmod_state(group,write)} {set group "w$group"}
  206.     if {$chmod_state(group,exec)} {set group "x$group"}
  207.     if {$chmod_state(other,read)} {set other "r$other"}
  208.     if {$chmod_state(other,write)} {set other "w$other"}
  209.     if {$chmod_state(other,exec)} {set other "x$other"}
  210.     if {$chmod_state(special,setuid)} {set user "s$user"}
  211.     if {$chmod_state(special,setgid)} {set group "s$group"}
  212.     if {$chmod_state(special,sticky)} {set all "t$all"}
  213.     if {$user != ""} {
  214.       set arg "u-$user"
  215.     }
  216.     if {$group != ""} {
  217.       if {$arg != ""} { set arg ",$arg" }
  218.       set arg "g-$group$arg"
  219.     }
  220.     if {$other != ""} {
  221.       if {$arg != ""} { set arg ",$arg" }
  222.       set arg "o-$other$arg"
  223.     }
  224.     if {$all != ""} {
  225.       if {$arg != ""} { set arg ",$arg" }
  226.       set arg "a-$all$arg"
  227.     }
  228.     set chmod_arg $arg
  229.   }
  230.   if {$chmod_recurse} {
  231.     set chmod_arg "-R $chmod_arg"
  232.   }
  233.  
  234.   set glob(enableautoupdate) $oldena
  235.   if {$chmod_cancel} {set chmod_arg ""}
  236.   unset chmod_state chmod_orig chmod_action chmod_recurse chmod_cancel
  237. #  puts "$chmod_arg"
  238.   return $chmod_arg
  239. }
  240.  
  241. proc ChmodSetAdd { } {
  242.   global chmod_state chmod_orig
  243.   foreach i [array names chmod_orig] {
  244.     set chmod_state($i) 0
  245.   }
  246. }
  247.  
  248. proc ChmodSetDel { } {
  249.   global chmod_state chmod_orig
  250.   foreach i [array names chmod_orig] {
  251.     set chmod_state($i) 0
  252.   }
  253. }
  254.  
  255. proc ChmodSetSet { } {
  256.   global chmod_state chmod_orig
  257.   foreach i [array names chmod_orig] {
  258.     set chmod_state($i) $chmod_orig($i)
  259.   }
  260. }
  261.  
  262.